package com.hbnu.system.core.base;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * 分页数据封装类
 */
public class CommonPage<T> {

    @ApiModelProperty(value = "当前页")
    private Long pageNum;
    @ApiModelProperty(value = "每页数量")
    private Long pageSize;
    @ApiModelProperty(value = "总页数")
    private Long totalPage;
    @ApiModelProperty(value = "总记录数")
    private Long total;
    @ApiModelProperty(value = "数据")
    private List<T> list;
    @ApiModelProperty(value = "量化分合计")
    private float figure;



    /**
     * 将 MyBatis-Plus 分页结果转为 CommonPage（关键属性映射）
     */
    public static <T> CommonPage<T> restPage(IPage<T> pageInfo) {
        CommonPage<T> result = new CommonPage<>();
        result.setTotalPage(pageInfo.getPages());   // 总页数（正确映射）
        result.setPageNum(pageInfo.getCurrent());   // 当前页（从 1 开始）
        result.setPageSize(pageInfo.getSize());     // 每页大小
        result.setTotal(pageInfo.getTotal());       // 总记录数（核心修复：此处应为 pageInfo.getTotal()）
        result.setList(pageInfo.getRecords());      // 数据列表
        return result;
    }


    public Long getPageNum() {
        return pageNum;
    }

    public void setPageNum(Long pageNum) {
        this.pageNum = pageNum;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Long totalPage) {
        this.totalPage = totalPage;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public float getFigure() {
        return figure;
    }

    public void setFigure(float figure) {
        this.figure = figure;
    }
}
